//
//  def_declarator.h
//  compilation
//
//  Created by Kevin Le perf on 17/01/12.
//  Copyright (c) 2012 e2co technologie. All rights reserved.
//

#ifndef compilation_def_declarator_h
#define compilation_def_declarator_h

/*
 
 declarator
 : IDENTIFIER   {printf("declarator\n");}
 | '(' declarator ')' {printf("declarator\n");}
 | declarator '[' CONSTANT ']' {printf("declarator\n");}
 | declarator '[' ']' {printf("declarator\n");}
 | declarator '(' parameter_list ')' {printf("declarator\n");}
 | declarator '(' ')' {printf("declarator\n");}
 ;
 */

struct def_declarator{
	void * parent;
	int type;
	char * identifier;
	char * constant;
	struct def_declarator * declarator;
	struct def_parameter_list * parameter_list;
};

struct def_declarator * declarator_create(void * parent){
	struct def_declarator * d = malloc(sizeof(*d));
	d->type = 0;
	d->parent = parent;
	return d;
}

void declarator_print(struct def_declarator * d){
	switch(d->type){
	case 1:
		printf("%s",d->identifier);
		break;
	case 2:
		printf("(");
		declarator_print(d->declarator);
		printf(")");
		break;
	case 3:
		declarator_print(d->declarator);
		printf("[%s]", d->constant);
		break;
	case 4:
		declarator_print(d->declarator);
		printf("[]");
		break;
	case 5:
		declarator_print(d->declarator);
		printf("(");
		parameter_list_print(d->parameter_list);
		printf(")");
		break;
	case 6:
		declarator_print(d->declarator);
		printf("()");
		break;
	}
}
#endif
